package com.hq.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hq.entity.QuestionType;
import com.hq.mapper.QuestionTypeMapper;
import com.hq.service.QuestionTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class QuestionTypeServiceImpl implements QuestionTypeService {
    @Autowired
    private QuestionTypeMapper questionTypeMapper;

    //查询所有题型
    @Override
    public List<QuestionType> findAll() {
        return questionTypeMapper.findAll();
    }

    //分页查询
    @Override
    public Map<String, Object> findByPage(int page, int size) {
        log.info("分页查询参数page:{},size:{}",page,size);
        Map<String,Object> map=new HashMap<>();
        Page<Object> objects = PageHelper.startPage(page, size);
        List<QuestionType> list = questionTypeMapper.findAll();
        map.put("list",list);
        map.put("total",objects.getTotal());
        return map;
    }

    //添加题型
    @Override
    public int addQuestionType(QuestionType questionType) {
        log.info("添加的题型{}",questionType);
        return questionTypeMapper.addQuestionType(questionType);
    }

    //单行删除题型
    @Override
    public int delType(int tid) {
        log.info("删除的题型id{}",tid);
        return questionTypeMapper.delType(tid);
    }

    //批量删除题型
    @Override
    public int delTypes(String ids) {
        log.info("批量删除的题型id{}",ids);
        return questionTypeMapper.delTypes(ids);
    }

    //编辑题型
    @Override
    public int editQuestionType(QuestionType questionType) {
        log.info("编辑的题型{}",questionType);
        return questionTypeMapper.editType(questionType);
    }
}
